package com.gxa.service.getmoneysevice.getMoneyServiceImpl;

import com.gxa.dao.getmoney.GetMoneyMapper;
import com.gxa.service.getmoneysevice.GetMoneyService;
import com.gxa.util.SqlSessionFactoryUtils;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;

import java.util.HashMap;
import java.util.Map;


public class GetMoneyServiceImpl implements GetMoneyService {


    @Override
    public float getPriceByid(int id) {
        SqlSessionFactory sqlSessionFactory = SqlSessionFactoryUtils.getSqlSessionFactory();
        SqlSession sql = sqlSessionFactory.openSession(true);
        GetMoneyMapper mapper = sql.getMapper(GetMoneyMapper.class);
        float v = mapper.selectPrinceById(id);
        return v;
    }

    @Override
    public Float findPriceByname(String s) {
        SqlSessionFactory sqlSessionFactory = SqlSessionFactoryUtils.getSqlSessionFactory();
        SqlSession sql = sqlSessionFactory.openSession(true);
        GetMoneyMapper mapper = sql.getMapper(GetMoneyMapper.class);
        Float priceByName = mapper.findPriceByName(s);
        return priceByName;
    }

    @Override
    public String findName(String barcode) {
        SqlSessionFactory sqlSessionFactory = SqlSessionFactoryUtils.getSqlSessionFactory();
        SqlSession sql = sqlSessionFactory.openSession(true);
        GetMoneyMapper mapper = sql.getMapper(GetMoneyMapper.class);
        String name = mapper.findName(barcode);
        return name;
    }

    @Override
    public float findPrice(String barcode) {
        SqlSessionFactory sqlSessionFactory = SqlSessionFactoryUtils.getSqlSessionFactory();
        SqlSession sql = sqlSessionFactory.openSession(true);
        GetMoneyMapper mapper = sql.getMapper(GetMoneyMapper.class);
        float price = mapper.findPrice(barcode);
        return price;
    }

    @Override
    public Boolean addGoods(String barcode, Integer count) {
        SqlSessionFactory sqlSessionFactory = SqlSessionFactoryUtils.getSqlSessionFactory();
        SqlSession sql = sqlSessionFactory.openSession(true);
        GetMoneyMapper mapper = sql.getMapper(GetMoneyMapper.class);
        Map<String ,Object> map = new HashMap<>();
        map.put("count",count);
        map.put("barcode",barcode);
        Boolean aBoolean = mapper.updateCount(map);
        return aBoolean;
    }
}